<template>
    <div id="login">
        <div id="loginBox">
            <div class="g_pic" align="center">
                <img src="../../assets/picture/EPS.png" style="height: 70px;width: 70px"/>
            </div>
            <div class="g_pic" align="center">
                <span>管理员登录</span>
            </div>
            <el-form ref="AdminFormRef" :model="AdminForm" :rules="AdminRules" class="Admin_form" label-width="0px">
                <el-form-item prop="mname" class="inps">
                    <el-input v-model="AdminForm.mname" prefix-icon="iconfont icon-yonghutubiao"></el-input>
                    <span id="nameInfo"></span>
                </el-form-item>
                <el-form-item prop="password" class="inps">
                    <el-input type="password" v-model="AdminForm.password"
                              prefix-icon="iconfont icon-mima"></el-input>
                    <span id="numberInfo"></span>
                </el-form-item>

                <el-form-item class="btns" align="center">
                    <!--@click="Login = true"--><!--更改开启滑块验证-->
                    <el-button type="primary" class="submitBtn" @click="AdminLogin">登录</el-button>
                    <el-button type="info" class="submitBtn"  @click="resetForm()">重置</el-button>
                </el-form-item>
            </el-form>


            <el-dialog
                    title="提示"
                    :visible.sync="Login"
                    width="30%">
                <div class="verification-slide">
                    <slide-verify
                            :l="42"
                            :r="10"
                            :w="360"
                            :h="155"
                            :accuracy ='4'
                            slider-text="拖动左边滑块完成上方拼图"
                            @success="onSuccess"
                            @fail="onFail">
                    </slide-verify>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                AdminForm: {
                    managerID:"",
                    mid:"",
                    mname: "admin",
                    password: "123456",
                },
                Login: false,

                AdminRules: {
                    mname: [{
                        required: true,
                        message: '用户名为必填项',
                        trigger: 'blur'
                    },
                        {
                            min: 2,
                            max: 8,
                            message: '长度在 2 到 8 个字符',
                            trigger: 'blur'
                        }
                    ],
                    password: [{
                        required: true,
                        message: '密码为必填项',
                        trigger: 'blur'
                    },],
                }
            };
        },
        methods: {
            resetForm() {
                this.$refs.AdminFormRef.resetFields()
            },

            onSuccess() {
                console.log('滑块验证通过');
                this.Login = false;
                this.AdminLogin();
            },
            onFail() {
                console.log('滑块验证不通过')
            },

            AdminLogin() {
                this.$refs.AdminFormRef.validate(async valid => {
                    if(!valid) return;
                    const{data:res}= await this.$http.post("AdminLogin",this.AdminForm);
                    this.AdminForm = res.Manager;
                    console.log(res);
                    if(res.flag==="ok"){
                        this.$message.success("成功");
                        window.sessionStorage.setItem('managerID', this.AdminForm.managerID);
                        window.sessionStorage.setItem("mid",this.AdminForm.mid);
                        window.sessionStorage.setItem('username', this.AdminForm.mname);
                        window.sessionStorage.setItem('password', this.AdminForm.password);
                        await this.$router.push({path: "/managerHome"});
                    }else{
                        this.$message.error("失败");
                        /*下面代码是用来，刷新当前页面，用来更新滑块验证动画*/
                        await this.$router.push({path: "/404"});
                        await this.$router.push({path: "/login"})
                    }
                })
            },
        }
    };
</script>

<style lang='less' scoped>
    #login {
        width: 100vw;
        padding: 0;
        margin: 0;
        height: 100vh;
        font-size: 16px;
        background-repeat: no-repeat;
        background-position: left top;
        background-color: #242645;
        color: #fff;
        font-family: "Source Sans Pro";
        background-size: 100%;
        background-image: url(../../assets/picture/bj.png);
        position: relative;

        #bgd {
            height: 100vh;
            width: 100vw;
            overflow: hidden;
        }

        #loginBox {
            width: 400px;
            height: 250px;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            padding: 50px 40px 40px 40px;
            box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
            opacity: 1;
            background: linear-gradient(230deg,
            rgba(53, 57, 74, 0) 0%,
            rgb(0, 0, 0) 100%);

            /deep/ .inps input {
                border: none;
                color: #fff;
                background-color: transparent;
                font-size: 18px;
            }

            .submitBtn {
                background-color: transparent;
                color: #39f;
                width: 100px;
            }

            .iconfont {
                color: #fff;
            }
        }
    }

    .Admin_form {
        padding: 0 20px;
    }
</style>
